//
//  EXRequestMessage.m
//  Edaox
//
//  Created by cao pan on 7/10/14.
//  Copyright (c) 2014 edaox. All rights reserved.
//

#import "EXRequestMessage.h"
#import "NSDate+Extension.h"
#import "NSString+Extension.h"

NSString * const EX_REQUEST_METHOD_GET = @"GET";
NSString * const EX_REQUEST_METHOD_POST = @"POST";

@implementation EXRequestMessage

@synthesize  requestBody = _requestBody;
@synthesize  requestPath = _requestPath;
@synthesize  requestMethod = _requestMethod;

- (id)init
{
    self = [super init];
    if (self) {
        _requestBody = [[NSMutableDictionary alloc] init];
        _requestMethod = EX_REQUEST_METHOD_GET;
        _isCryptParameters = NO;
    }
    return self;
}

- (NSArray *)allKeys
{
    return [_requestBody allKeys];
}

- (NSArray *)allValues
{
    return [_requestBody allValues];
}


#pragma mark ------ getter --------


- (NSString*)stringForKey:(NSString*)key
{
    return [_requestBody objectForKey:key];
}

- (NSInteger)intForKey:(NSString*)key
{
	return [[self stringForKey:key] intValue];
}

- (double)doubleForKey:(NSString*)key
{
	return [[self stringForKey:key] longLongValue];
}

- (BOOL)boolForKey:(NSString*)key
{
	return [[self stringForKey:key] boolValue];
}

- (NSDate*)dateForKey:(NSString*)key
{
    return [self dateForKey:key withFormat:@"yyyy-MM-dd HH:mm:ss"];
}

- (NSDate*)dateForKey:(NSString*)key withFormat:(NSString*)format
{
	return [NSDate dateWithString:[self stringForKey:key] format:format];
}

- (NSData*)dataForKey:(NSString*)key
{
    return nil;
}

#pragma mark ------ setter --------

- (void)setString:(NSString*)value forKey:(NSString*)key
{
    assert(key != nil);
    if (value == nil){
        [_requestBody removeObjectForKey:key];
    }
    else{
        [_requestBody setObject:value forKey:key];
    }
    
}

- (void)setInt:(NSInteger)value forKey:(NSString*)key
{
	[self setString:[NSString stringWithFormat:@"%ld", (long)value] forKey:key];
}

- (void)setDouble:(double)value forKey:(NSString*)key
{
	[self setString:[NSString stringWithFormat:@"%f", value] forKey:key];
}

- (void)setBool:(BOOL)value forKey:(NSString*)key
{
	[self setString:(value == NO) ? @"0" : @"1" forKey:key];
}

- (void)setDate:(NSDate*)value forKey:(NSString*)key
{
	[self setDate:value forKey:key withFormat:@"yyyy-MM-dd HH:mm:ss"];
}


- (void)setDate:(NSDate*)value forKey:(NSString*)key withFormat:(NSString*)format
{
	[self setString:[NSString stringWithDate:value format:format] forKey:key];
}

- (void)setData:(NSData*)value forKey:(NSString*)key
{
}


- (void)setImageData:(NSData *)value forKey:(NSString *)key
{
    [_requestBody setObject:value forKey:key];
}


@end
